package top.lingma.result;

import lombok.*;

/**
 * @author yui
 * @date 2019年05月20日 下午4:54
 */
@Getter
@Setter
@Builder
@NoArgsConstructor
@AllArgsConstructor
public class ApiResult {
    private Integer code;
    private String msg;
    private Object data;
    private Long date=System.currentTimeMillis();

    public static ApiResult success = ApiResult.builder().code(200).msg("成功").build();
    public static ApiResult error = ApiResult.builder().code(9009).msg("失败").build();

    public static ApiResult success(Object data) {
        return ApiResult.builder().code(200).msg("成功").data(data).build();
    }

    public static ApiResult success() {
        return success;
    }

    public static ApiResult unauthorized() {
        return ApiResult.builder().code(401).msg("当前请求需要用户登录").build();
    }

    public static ApiResult error(Object data) {
        return ApiResult.builder().code(9009).msg("失败").data(data).build();
    }

    public static ApiResult error() {
        return error;
    }
}
